package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;

/**
 * @description <p>频道信息 业务实现</p>
 *
 * @version 1.0
 * @package com.itheima.admin.service.impl
 */
@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Override
    public PageResultVo<AdChannel> pageList(ChannelPageRequestDto dto) {
        //1. 分页参数设置
        IPage<AdChannel> pageInfo = new Page(dto.getPage(),dto.getSize());
        //2. 构建查询条件
        LambdaQueryWrapper<AdChannel> queryWrapper = Wrappers.<AdChannel>lambdaQuery()
            //2.1 名称使用模糊查询
            .like(StringUtils.isNotEmpty(dto.getName()), AdChannel::getName, dto.getName())
            //2.2 状态使用精确查询
            .eq(null != dto.getStatus(), AdChannel::getStatus, dto.getStatus());
        //3. 分页查询
        page(pageInfo, queryWrapper);
        //4. 构建分页结果并返回
        return PageResultVo.pageResult(pageInfo.getCurrent(), pageInfo.getSize(), pageInfo.getTotal(), pageInfo.getRecords());
    }
}